import * as THREE from "three";
// 导入场景
import scene from "@/three/scene"

import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader.js"
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"
import modifyCityMaterial from '../modify/modifyCityMaterial';
import FlyLine from './FlyLine';
import FlyLineShader from "./FlyLineShader"
import MeshLine from "./MeshLine"
import LightWall from "./LightWall"
import LightRadar from './LightRadar';
import AlarmSprite from './AlarmSprite';

export default function cerateCity(){
    // console.log("----------cerateCity----------");
    const gltfLoader = new GLTFLoader();
    gltfLoader.load("./model/city2.glb",(gltf)=>{
        // console.log(gltf)
        gltf.scene.traverse((item)=>{
            if(item.type == "Mesh"){
                item.material = new THREE.MeshBasicMaterial({
                    color:new THREE.Color(0x0c0e6f)
                })
                modifyCityMaterial(item);
                // console.log(item);
                if(item.name == "Layerbuildings"){
                    // 根据形状生成边缘几何体
                    const meshLine = new MeshLine(item.geometry);
                    //设置缩放
                    const size = item.scale.x * 1.001;
                    meshLine.mesh.scale.set(size,size,size)
                    scene.add(meshLine.mesh)
                }
            }
        });
        scene.add(gltf.scene)

        // const flyLine = new FlyLine();
        // scene.add(flyLine.mesh)

        // const flyLineShader = new FlyLineShader({ x: -18, z: 0 });
        // scene.add(flyLineShader.mesh)

        
        // const lightWall = new LightWall();
        // scene.add(lightWall.mesh)
        // // 获取物体的高度差
        // lightWall.mesh.geometry.computeBoundingBox();
        // let {min,max} = lightWall.mesh.geometry.boundingBox;
        // let uHeight = max.y - min.y;
    
        // lightWall.material.uniforms.uTopColor = {
        //     value:new THREE.Color("#ff0016")
        // }
        // lightWall.material.uniforms.uHeight = {
        //     value:uHeight
        // }

        // const lightRadar = new LightRadar(5,{x:6,z:-2.1});
        // scene.add(lightRadar.mesh)

        // const alarmSprite = new AlarmSprite();
        // scene.add(alarmSprite.mesh)
        // alarmSprite.onClick(function (e) {
        //     console.log("警告信息", e)
        // });
    })
}